import { Message } from 'element-ui'
import axios from '../../js/axios'
import qs from 'qs' // 序列化时候用到
export default {
  namespaced: true,
  state: {},
  getters: {},
  mutations: {},
  actions: {
    // post方式 + 序列化格式
    async getInitData ({ commit }, params) {
      try {
        let { data: { code, data, msg } } = await axios.post('/app/admin/setting/get-setting-l', qs.stringify(params))
        return new Promise((resolve, reject) => {
          if (code === 0) {
            resolve(data)
          } else {
            Message.error(msg)
            reject(data)
          }
        })
      } catch (err) {
        Message.error('服务器出错')
        console.log(err)
      }
    },
    async update ({ commit }, params) {
      try {
        let { data: { code, data, msg } } = await axios.post('/app/admin/setting/update-setting-l', qs.stringify(params))
        return new Promise((resolve, reject) => {
          if (code === 0) {
            resolve(data)
          } else {
            Message.error(msg)
            reject(data)
          }
        })
      } catch (err) {
        Message.error('服务器出错')
        console.log(err)
      }
    }
  }
}
